package com.blb.controller;

import com.blb.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

@Controller
public class UserController {

    @RequestMapping("login")
    public String login(@RequestHeader("Host")String host, @CookieValue("JSESSIONID") String sessionId , User user, Model model){
        System.out.println(host);
        System.out.println(sessionId);
        System.out.println(user);

        if(!"zs".equals(user.getName()) || !"123".equals(user.getPwd())){
            //登录失败
            model.addAttribute("msg", "用户名或密码错误");
            //转发
            return "login.jsp";
        }else{
            //登录成功
            //重定向
            return "redirect:/index.jsp";
        }
    }

    /**
     * 直接响应文本
     * @return
     */
    @ResponseBody
    @RequestMapping("ajax")
    public String hello(){
        return "测试接口";
    }

    @ResponseBody
    @RequestMapping("user")
    public User hello2(){
        User user = new User();
        user.setId(1);
        user.setName("张三");
        user.setPwd("123");
        user.setSex('男');
        user.setTel("123456");
        return user;
    }

    /**
     * 接收中文乱码处理
     * @param name
     * @return
     */
    @ResponseBody
    @RequestMapping("test")
    public String test(String name){
        System.out.println(name);
        return "哈哈";
    }
}
